<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon.ico">
  <link rel="mask-icon" href="/favicon.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="/lib/@fortawesome/fontawesome-free/css/all.min.css" integrity="sha256-5eIC48iZUHmSlSUz9XtjRyK2mzQkHScZY1WdMaoz74E=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/animate.css/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"blog.dqv5.com","root":"/","images":"/images","scheme":"Mist","darkmode":true,"version":"8.21.1","exturl":false,"sidebar":{"position":"right","width_expanded":320,"width_dual_column":240,"display":"always","padding":18,"offset":12},"hljswrap":true,"copycode":{"enable":true,"style":null},"fold":{"enable":true,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"gitalk","storage":true,"lazyload":false,"nav":null,"activeClass":"gitalk"},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false,"trigger":"auto"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="用html5_canvas实现2048网页游戏">
<meta property="og:type" content="article">
<meta property="og:title" content="用html5_canvas实现2048网页游戏">
<meta property="og:url" content="http://blog.dqv5.com/2016/05/13/2048/index.html">
<meta property="og:site_name" content="dqv5.com">
<meta property="og:description" content="用html5_canvas实现2048网页游戏">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2016-05-13T15:19:04.000Z">
<meta property="article:modified_time" content="2024-11-23T11:58:37.867Z">
<meta property="article:author" content="du qian">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://blog.dqv5.com/2016/05/13/2048/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://blog.dqv5.com/2016/05/13/2048/","path":"2016/05/13/2048/","title":"用html5_canvas实现2048网页游戏"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>用html5_canvas实现2048网页游戏 | dqv5.com</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js"></script>
  <script async src="https://hm.baidu.com/hm.js?1752ae624eedea5ce859335ad2f0e657"></script>







  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">dqv5.com</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">49</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">20</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">61</span></a></li><li class="menu-item menu-item-留言板"><a href="/message-board/" rel="section"><i class="fa fa-comments fa-fw"></i>留言板</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#html%E4%BB%A3%E7%A0%81"><span class="nav-text">html代码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#css%E4%BB%A3%E7%A0%81"><span class="nav-text">css代码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#js%E4%BB%A3%E7%A0%81"><span class="nav-text">js代码</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="du qian"
      src="/images/soccer.jpg">
  <p class="site-author-name" itemprop="name">du qian</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">61</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">20</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">49</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/duqian42707" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;duqian42707" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://stackoverflow.com/duqian42707" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;duqian42707" rel="noopener me" target="_blank"><i class="fab fa-stack-overflow fa-fw"></i>StackOverflow</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/duqian42707" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;duqian42707" rel="noopener me" target="_blank"><i class="fas fa-link fa-fw"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://duqian42707.github.io/qiniu-host" title="图床 → https:&#x2F;&#x2F;duqian42707.github.io&#x2F;qiniu-host" rel="noopener me" target="_blank"><i class="far fa-image fa-fw"></i>图床</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://blog.dqv5.com/2016/05/13/2048/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/soccer.jpg">
      <meta itemprop="name" content="du qian">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="dqv5.com">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="用html5_canvas实现2048网页游戏 | dqv5.com">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          用html5_canvas实现2048网页游戏
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2016-05-13 15:19:04" itemprop="dateCreated datePublished" datetime="2016-05-13T15:19:04+00:00">2016-05-13</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-11-23 11:58:37" itemprop="dateModified" datetime="2024-11-23T11:58:37+00:00">2024-11-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/lessons/" itemprop="url" rel="index"><span itemprop="name">lessons</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>摘要：用html5_canvas实现2048网页游戏</p>
<!-- more -->
<p><a href="/pages/2048.html">查看示例</a></p>
<h4 id="html代码"><a href="#html代码" class="headerlink" title="html代码"></a>html代码</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;main&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">canvas</span> <span class="attr">id</span>=<span class="string">&quot;myCanvas&quot;</span> <span class="attr">width</span>=<span class="string">&quot;300&quot;</span> <span class="attr">height</span>=<span class="string">&quot;300&quot;</span> &gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;bottom&quot;</span> <span class="attr">style</span>=<span class="string">&quot;display: none;&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;W&quot;</span> <span class="attr">class</span>=<span class="string">&quot;con&quot;</span>&gt;</span>W<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;A&quot;</span> <span class="attr">class</span>=<span class="string">&quot;con&quot;</span>&gt;</span>A<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;S&quot;</span> <span class="attr">class</span>=<span class="string">&quot;con&quot;</span>&gt;</span>S<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;D&quot;</span> <span class="attr">class</span>=<span class="string">&quot;con&quot;</span>&gt;</span>D<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;tips&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">h4</span>&gt;</span>方向控制：WASD、↑↓←→、手指滑动<span class="tag">&lt;/<span class="name">h4</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="css代码"><a href="#css代码" class="headerlink" title="css代码"></a>css代码</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span><br><span class="line"><span class="language-css">        <span class="selector-tag">body</span> &#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">margin</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">padding</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css">        <span class="selector-id">#myCanvas</span> &#123;</span></span><br><span class="line"><span class="language-css">            <span class="comment">/*border: red 1px solid;*/</span></span></span><br><span class="line"><span class="language-css">            <span class="attribute">margin</span>: <span class="number">10px</span> auto;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">border-radius</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">display</span>: block;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">        <span class="selector-class">.bottom</span>&#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">text-align</span>: center;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">        <span class="selector-class">.bottom</span>&gt;<span class="selector-tag">div</span>&#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">margin-top</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">        <span class="selector-class">.con</span>&#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">color</span>:white;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">background-color</span>: green;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">display</span>: inline-block;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">width</span>:<span class="number">50px</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">height</span>:<span class="number">50px</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">line-height</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">text-align</span>: center;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">        <span class="selector-class">.tips</span>&#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">text-align</span>: center;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="js代码"><a href="#js代码" class="headerlink" title="js代码"></a>js代码</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">&quot;http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script type=&quot;text/javascript&quot;&gt;</span><br><span class="line">        $(function () &#123;</span><br><span class="line">            var canvas = document.getElementById(&quot;myCanvas&quot;);</span><br><span class="line">            var context = canvas.getContext(&quot;2d&quot;);</span><br><span class="line">            var d=12;</span><br><span class="line">            var a=60;</span><br><span class="line">            var directMap = &#123;</span><br><span class="line">                &#x27;W&#x27;:0,</span><br><span class="line">                &#x27;S&#x27;:1,</span><br><span class="line">                &#x27;A&#x27;:2,</span><br><span class="line">                &#x27;D&#x27;:3,</span><br><span class="line">                &#x27;&amp;&#x27;:0,</span><br><span class="line">                &#x27;(&#x27;:1,</span><br><span class="line">                &#x27;%&#x27;:2,</span><br><span class="line">                &#x27;\&#x27;&#x27;:3</span><br><span class="line">            &#125;;</span><br><span class="line">            //当前屏幕上所有的块</span><br><span class="line">            var blocks = [</span><br><span class="line">                0, 0, 0, 0,</span><br><span class="line">                2, 0, 0, 0,</span><br><span class="line">                0, 0, 2, 0,</span><br><span class="line">                0, 0, 0, 2</span><br><span class="line">            ];</span><br><span class="line">            var newBlocks=[];//blocks的备份，用来保存目标状态</span><br><span class="line">            var newIndex=[];//保存每个块的目标位置，如newIndex[4]=8表示第4个块移动到第8个块的位置（下移一格）</span><br><span class="line">            //生成新数字</span><br><span class="line">            var another_num = function()&#123;</span><br><span class="line">                var empty = [];</span><br><span class="line">                for(var i = 0 ; i &lt; blocks.length; i++)&#123;</span><br><span class="line">                    if(blocks[i]==0)&#123;</span><br><span class="line">                        empty.push(i)</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                var idx = empty[parseInt(Math.random() * empty.length)];</span><br><span class="line">                blocks[idx] = Math.random() &lt; 0.8 ? 2 : 4;</span><br><span class="line">                drawBlock(idx)</span><br><span class="line">            &#125;;</span><br><span class="line">            //通过数组下标（0-15）计算4个相关的值</span><br><span class="line">            var getPositon = function(n)&#123;</span><br><span class="line">                var obj = &#123;&#125;;</span><br><span class="line">                obj.i = n%4;//第几列（从0开始）</span><br><span class="line">                obj.j = parseInt(n/4);//第几行（从0开始）</span><br><span class="line">                obj.x = (obj.i+1)*d+obj.i*a;//横坐标</span><br><span class="line">                obj.y = (obj.j+1)*d+obj.j*a;//纵坐标</span><br><span class="line">                return obj;</span><br><span class="line">            &#125;;</span><br><span class="line">            //画单个块和数字，若不指定x，y的值，则由index计算得出</span><br><span class="line">            var drawBlock = function(index,dx,dy)&#123;</span><br><span class="line">                context.fillStyle = &#x27;#ECE0C8&#x27;;</span><br><span class="line">                var num = blocks[index];</span><br><span class="line">                if(num==0)return;</span><br><span class="line">                var x = getPositon(index).x;</span><br><span class="line">                var y = getPositon(index).y;</span><br><span class="line">                if (dx != null)x = dx;</span><br><span class="line">                if (dy != null)y = dy;</span><br><span class="line">                context.fillRect(x,y,a,a);</span><br><span class="line">                var fontSize = 30;</span><br><span class="line">                var l = num.toString().length;</span><br><span class="line">                if(l==4)&#123;</span><br><span class="line">                    fontSize=25</span><br><span class="line">                &#125;else if(l==5)&#123;</span><br><span class="line">                    fontSize=20</span><br><span class="line">                &#125;</span><br><span class="line">                context.font=&#x27;bold &#x27;+fontSize+&#x27;px Meiryo&#x27;;</span><br><span class="line">                context.fillStyle = &#x27;#7C736A&#x27;;</span><br><span class="line">                x=x+(a-fontSize*2*l/3)/2;</span><br><span class="line">                y=y+(fontSize+a)/2;</span><br><span class="line"></span><br><span class="line">                context.fillText(num.toString(),x,y);</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            var merged=[];</span><br><span class="line">            //将cur合并到pre,若成功合并则返回pre，没合并则返回cur</span><br><span class="line">            var merge=function(pre , cur)&#123;</span><br><span class="line">                if(newBlocks[cur]!=0)&#123;</span><br><span class="line">                    if(newBlocks[pre]==0)&#123;</span><br><span class="line">                        newBlocks[pre]=newBlocks[cur];</span><br><span class="line">                        newBlocks[cur]=0;</span><br><span class="line">                        return pre</span><br><span class="line">                    &#125;else if(newBlocks[pre]==newBlocks[cur]&amp;&amp;merged.indexOf(pre)==-1)&#123;//已经合并过一此的pre块不再合并</span><br><span class="line">                        newBlocks[pre]*=2;</span><br><span class="line">                        newBlocks[cur]=0;</span><br><span class="line">                        merged.push(pre);</span><br><span class="line">                        return pre</span><br><span class="line">                    &#125;else&#123;</span><br><span class="line">                        return cur</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;else&#123;</span><br><span class="line">                    return cur</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            //块的合并；计算本次操作后每个块目标位置（保存至newIndex数组）</span><br><span class="line">            var getNewIndex = function (direct) &#123;</span><br><span class="line">                merged=[];</span><br><span class="line">                switch (direct) &#123;</span><br><span class="line">                    case 0:</span><br><span class="line">                        for (var j = 0; j &lt; 4; j++) &#123;</span><br><span class="line">                            for (var i = 0; i &lt; 4; i++) &#123;</span><br><span class="line">                                var k = 1;</span><br><span class="line">                                var index = 4*i+j;</span><br><span class="line">                                while (4 * (i - k) + j &gt;= 0) &#123;</span><br><span class="line">                                    index = merge(4 * (i - k) + j, 4 * (i - k + 1) + j);</span><br><span class="line">                                    if(index==4*i+j)break;</span><br><span class="line">                                    k++;</span><br><span class="line">                                &#125;</span><br><span class="line">                                newIndex[4*i+j]=index;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                        break;</span><br><span class="line">                    case 1:</span><br><span class="line">                        for (var j = 0; j &lt; 4; j++) &#123;</span><br><span class="line">                            for (var i = 3; i &gt;= 0; i--) &#123;</span><br><span class="line">                                var k = 1;</span><br><span class="line">                                var index = 4*i+j;</span><br><span class="line">                                while (4 * (i + k) + j &lt; blocks.length) &#123;</span><br><span class="line">                                    index = merge(4 * (i + k) + j, 4 * (i + k - 1) + j);</span><br><span class="line">                                    if(index==4*i+j)break;</span><br><span class="line">                                    k++;</span><br><span class="line">                                &#125;</span><br><span class="line">                                newIndex[4*i+j]=index;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                        break;</span><br><span class="line">                    case 2:</span><br><span class="line">                        for (var i = 0; i &lt; 4; i++) &#123;</span><br><span class="line">                            for (var j = 0; j &lt; 4; j++) &#123;</span><br><span class="line">                                var k = 1;</span><br><span class="line">                                var index = 4*i+j;</span><br><span class="line">                                while (j - k &gt;= 0) &#123;</span><br><span class="line">                                    index = merge(4 * i + j - k, 4 * i + j - k + 1);</span><br><span class="line">                                    if(index==4*i+j)break;</span><br><span class="line">                                    k++;</span><br><span class="line">                                &#125;</span><br><span class="line">                                newIndex[4*i+j]=index;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                        break;</span><br><span class="line">                    case 3:</span><br><span class="line">                        for (var i = 0; i &lt; 4; i++) &#123;</span><br><span class="line">                            for (var j = 3; j &gt;= 0; j--) &#123;</span><br><span class="line">                                var k = 1;</span><br><span class="line">                                var index = 4*i+j;</span><br><span class="line">                                while (j + k &lt; 4) &#123;</span><br><span class="line">                                    index = merge(4 * i + j + k, 4 * i + j + k - 1);</span><br><span class="line">                                    if(index==4*i+j)break;</span><br><span class="line">                                    k++;</span><br><span class="line">                                &#125;</span><br><span class="line">                                newIndex[4*i+j]=index;</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                        break;</span><br><span class="line">                    default:</span><br><span class="line">                        break;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            //动画结束后刷新每个块的信息，产生一个新的块</span><br><span class="line">            var stopMoving = function()&#123;</span><br><span class="line">                init();</span><br><span class="line">                for(var n=0;n&lt;blocks.length;n++)&#123;</span><br><span class="line">                    blocks[n]=newBlocks[n]+0;</span><br><span class="line">                    drawBlock(n)</span><br><span class="line">                &#125;</span><br><span class="line">                another_num()</span><br><span class="line">            &#125;;</span><br><span class="line">            //滑动操作</span><br><span class="line">            var moveBlocks = function(direct) &#123;</span><br><span class="line">                //先将所有块的当前状态复制到新数组中</span><br><span class="line">                for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                    newBlocks[n] = blocks[n] + 0</span><br><span class="line">                &#125;</span><br><span class="line">                //合并，计算本次操作后每个块目标位置</span><br><span class="line">                getNewIndex(direct);</span><br><span class="line"></span><br><span class="line">                //动画开始</span><br><span class="line">                var t = 0;</span><br><span class="line">                var int = setInterval(function () &#123;</span><br><span class="line">                    //初始化背景</span><br><span class="line">                    init();</span><br><span class="line">                    //画有数字的块</span><br><span class="line">                    switch (direct) &#123;</span><br><span class="line">                        case 0:</span><br><span class="line">                            var stop = true;</span><br><span class="line">                            for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                                if (blocks[n] == 0)continue;</span><br><span class="line">                                var x = getPositon(n).x;</span><br><span class="line">                                var y = getPositon(n).y;</span><br><span class="line">                                y -= d * 4 * t;//一点点地改变坐标 实现动画效果</span><br><span class="line">                                if (y &lt;= getPositon(newIndex[n]).y) &#123;//本块到达目标位置，不再动了</span><br><span class="line">                                    y = getPositon(newIndex[n]).y</span><br><span class="line">                                &#125; else &#123;//本块没有到达目标位置，动画不能停</span><br><span class="line">                                    stop = false</span><br><span class="line">                                &#125;</span><br><span class="line">                                drawBlock(n, null, y)</span><br><span class="line">                            &#125;</span><br><span class="line">                            if (stop) &#123;</span><br><span class="line">                                //动画结束，重新给数组赋值</span><br><span class="line">                                clearInterval(int);</span><br><span class="line">                                stopMoving()</span><br><span class="line">                            &#125;</span><br><span class="line">                            break;</span><br><span class="line">                        case 1:</span><br><span class="line">                            var stop = true;</span><br><span class="line">                            for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                                if (blocks[n] == 0)continue;</span><br><span class="line">                                var x = getPositon(n).x;</span><br><span class="line">                                var y = getPositon(n).y;</span><br><span class="line">                                y += d * 4 * t;</span><br><span class="line">                                //停止移动的条件：该块到达最终位置</span><br><span class="line">                                if (y &gt;= getPositon(newIndex[n]).y) &#123;</span><br><span class="line">                                    y = getPositon(newIndex[n]).y</span><br><span class="line">                                &#125; else &#123;</span><br><span class="line">                                    stop = false</span><br><span class="line">                                &#125;</span><br><span class="line">                                drawBlock(n, null, y)</span><br><span class="line">                            &#125;</span><br><span class="line"></span><br><span class="line">                            if (stop) &#123;</span><br><span class="line">                                //动画结束，重新给数组赋值</span><br><span class="line">                                clearInterval(int);</span><br><span class="line">                                stopMoving();</span><br><span class="line">                            &#125;</span><br><span class="line">                            break;</span><br><span class="line">                        case 2:</span><br><span class="line">                            var stop = true;</span><br><span class="line">                            for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                                if (blocks[n] == 0)continue;</span><br><span class="line">                                var x = getPositon(n).x;</span><br><span class="line">                                var y = getPositon(n).y;</span><br><span class="line">                                x -= d * 4 * t;</span><br><span class="line">                                if (x &lt;= getPositon(newIndex[n]).x) &#123;</span><br><span class="line">                                    x = getPositon(newIndex[n]).x</span><br><span class="line">                                &#125; else &#123;</span><br><span class="line">                                    stop = false</span><br><span class="line">                                &#125;</span><br><span class="line">                                drawBlock(n, x, null)</span><br><span class="line">                            &#125;</span><br><span class="line">                            if (stop) &#123;</span><br><span class="line">                                //动画结束，重新给数组赋值</span><br><span class="line">                                clearInterval(int);</span><br><span class="line">                                stopMoving()</span><br><span class="line">                            &#125;</span><br><span class="line">                            break;</span><br><span class="line">                        case 3:</span><br><span class="line">                            var stop = true;</span><br><span class="line">                            for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                                if (blocks[n] == 0)continue;</span><br><span class="line">                                var x = getPositon(n).x;</span><br><span class="line">                                var y = getPositon(n).y;</span><br><span class="line">                                x += d * 4 * t;</span><br><span class="line">                                if (x &gt;= getPositon(newIndex[n]).x) &#123;</span><br><span class="line">                                    x = getPositon(newIndex[n]).x</span><br><span class="line">                                &#125; else &#123;</span><br><span class="line">                                    stop = false</span><br><span class="line">                                &#125;</span><br><span class="line">                                drawBlock(n, x, null)</span><br><span class="line">                            &#125;</span><br><span class="line">                            if (stop) &#123;</span><br><span class="line">                                //动画结束，重新给数组赋值</span><br><span class="line">                                clearInterval(int);</span><br><span class="line">                                stopMoving()</span><br><span class="line">                            &#125;</span><br><span class="line">                            break;</span><br><span class="line">                    &#125;</span><br><span class="line">                    t++</span><br><span class="line">                &#125;, 20)</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            //滑屏监听</span><br><span class="line">            var startX,startY;</span><br><span class="line">            $(&#x27;#myCanvas&#x27;).bind(&quot;touchstart&quot;, function(e) &#123;</span><br><span class="line">                e.preventDefault();</span><br><span class="line">                startX = e.originalEvent.changedTouches[0].pageX;</span><br><span class="line">                startY = e.originalEvent.changedTouches[0].pageY;</span><br><span class="line">            &#125;);</span><br><span class="line">            $(&#x27;#myCanvas&#x27;).bind(&quot;touchend&quot;, function(e) &#123;</span><br><span class="line">                e.preventDefault();</span><br><span class="line">                var moveEndX = e.originalEvent.changedTouches[0].pageX;</span><br><span class="line">                var moveEndY = e.originalEvent.changedTouches[0].pageY;</span><br><span class="line">                var X = moveEndX - startX;</span><br><span class="line">                var Y = moveEndY - startY;</span><br><span class="line">                if ( Math.abs(Y) &gt; Math.abs(X) &amp;&amp; Y &lt; 0 ) &#123;//上</span><br><span class="line">                    moveBlocks(0)</span><br><span class="line">                &#125;else if ( Math.abs(Y) &gt; Math.abs(X) &amp;&amp; Y &gt; 0) &#123;//下</span><br><span class="line">                    moveBlocks(1)</span><br><span class="line">                &#125;else if ( Math.abs(X) &gt; Math.abs(Y) &amp;&amp; X &lt; 0 ) &#123;//左</span><br><span class="line">                    moveBlocks(2)</span><br><span class="line">                &#125;else if ( Math.abs(X) &gt; Math.abs(Y) &amp;&amp; X &gt; 0 ) &#123;//右</span><br><span class="line">                    moveBlocks(3)</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;);</span><br><span class="line">            //键盘监听</span><br><span class="line">            document.onkeydown = function (e) &#123;</span><br><span class="line">                var keynum, keychar;</span><br><span class="line">                if(window.event)&#123;       // IE</span><br><span class="line">                    keynum = e.keyCode;</span><br><span class="line">                &#125;</span><br><span class="line">                else if(e.which)&#123;       // Netscape/Firefox/Opera</span><br><span class="line">                    keynum = e.which;</span><br><span class="line">                &#125;</span><br><span class="line">                keychar = String.fromCharCode(keynum);</span><br><span class="line">                if([&#x27;W&#x27;, &#x27;S&#x27;, &#x27;A&#x27;, &#x27;D&#x27;,&#x27;&amp;&#x27;,&#x27;(&#x27;,&#x27;%&#x27;,&#x27;\&#x27;&#x27;].indexOf(keychar) &gt; -1)&#123;</span><br><span class="line">                        moveBlocks(directMap[keychar])</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            //按钮监听</span><br><span class="line">            var btns = document.getElementsByClassName(&quot;con&quot;);</span><br><span class="line">            for(var i=0;i&lt;btns.length;i++)&#123;</span><br><span class="line">                btns[i].onclick = function() &#123;</span><br><span class="line">                    moveBlocks(directMap[this.id])</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            //初始化 开始</span><br><span class="line">            var init = function() &#123;</span><br><span class="line">                //画背景</span><br><span class="line">                context.clearRect(0, 0, 300, 300);</span><br><span class="line">                context.fillStyle = &#x27;#B8AF9E&#x27;;</span><br><span class="line">                context.fillRect(0, 0, 300, 300);</span><br><span class="line">                context.fillStyle = &#x27;#CCC0B2&#x27;;</span><br><span class="line">                for (var i = 1; i &lt;= 4; i++) &#123;</span><br><span class="line">                    for (var j = 1; j &lt;= 4; j++) &#123;</span><br><span class="line">                        context.fillRect(i * d + (i - 1) * a, j * d + (j - 1) * a, a, a)</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;;</span><br><span class="line">            init();</span><br><span class="line">            //画有数字的块</span><br><span class="line">            for (var n = 0; n &lt; blocks.length; n++) &#123;</span><br><span class="line">                drawBlock(n)</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        &#125;)</span><br><span class="line">    &lt;/script&gt;</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.jpg" alt="du qian 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.jpg" alt="du qian 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>


        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2016/05/13/clock/" rel="prev" title="用html5_canvas画时钟">
                  <i class="fa fa-angle-left"></i> 用html5_canvas画时钟
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2016/05/13/snake/" rel="next" title="用html5_canvas实现贪吃蛇">
                  用html5_canvas实现贪吃蛇 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments gitalk-container"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">冀ICP备17034993号-1 </a>
  </div>
  <div class="copyright">
    &copy; 2016 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">du qian</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>
  <div class="upyun-league">
    本网站由<a target="_blank" rel="noopener" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="border-bottom: none;">
      <img src="/images/upyun_logo.png" alt="又拍云" style="display: inline;height: 30px;vertical-align: bottom;"/>
    </a>提供CDN加速/云存储服务
  </div>


    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/duqian42707" class="github-corner" title="在 GitHub 上关注我" aria-label="在 GitHub 上关注我" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="/lib/animejs/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/sidebar.js"></script><script src="/js/next-boot.js"></script>

  <script src="/lib/hexo-generator-searchdb/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>


  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":"forest","js":{"url":"/lib/mermaid/dist/mermaid.min.js","integrity":"sha256-G8ouPAnw4zzMbnAenHnVz6h9XpKbNdOkrqTh7AadyHs="}}</script>
  <script src="/js/third-party/tags/mermaid.js"></script>





  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




<link rel="stylesheet" href="/lib/gitalk/dist/gitalk.css" integrity="sha256-AJnUHL7dBv6PGaeyPQJcgQPDjt/Hn/PvYZde1iqfp8U=" crossorigin="anonymous">

<script class="next-config" data-name="gitalk" type="application/json">{"enable":true,"github_id":"duqian42707","repo":"blog-comment","client_id":"c9f48bc2fea3d4ce5d93","client_secret":"154d6227d3d7b532b36bfc1ce030121f0263ac90","admin_user":"duqian42707","distraction_free_mode":false,"proxy":"https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token","language":"zh-CN","js":{"url":"/lib/gitalk/dist/gitalk.min.js","integrity":"sha256-MVK9MGD/XJaGyIghSVrONSnoXoGh3IFxLw0zfvzpxR4="},"path_md5":"fdbedb6aac73c9904e946678d25e9c3a"}</script>
<script src="/js/third-party/comments/gitalk.js"></script>

</body>
</html>
